#!/bin/bash
function Usage() {
    echo "Usage : $0"
}

if [[ $# -ge 1 ]];then
    Usage
    exit 1
fi
#获取系统时间
NowTime=`date +"%Y-%m-%d %H:%M:%S"`

eval `df -T -m -x tmpfs -x devtmpfs | tail -n +2 \
    | awk -v DiskSum=0 -v LeftSum=0 '{printf("partsum["NR"]=%d;partleft["NR"]=%d;partname["NR"]=%s;partusage["NR"]=%s;", $3, $5, $7, $6);DiskSum+=$3;LeftSum+=$5} END {printf("partnum=%d;DiskSum=%d;LeftSum=%d", NR, DiskSum, LeftSum)}'`

#总的磁盘
diskusage=`echo "scale=2; 100-${LeftSum}*100/${DiskSum}" | bc`
echo "${NowTime} 0 all ${DiskSum} ${LeftSum} ${diskusage}%"

#输出分区
for (( i = 1; i <= ${partnum}; i++ ));do
    echo "$NowTime 1 ${partname[$i]} ${partsum[$i]} ${partleft[$i]} ${partusage[$i]}"
done

